import { Catch, httpError, MidwayHttpError } from '@midwayjs/core';
import { Context } from '@midwayjs/koa';

// token无效 捕获 401 错误
@Catch(httpError.UnauthorizedError)
export class UnauthorizedFilter {
  async catch(err: MidwayHttpError, ctx: Context) {
    return {
      success: false,
      errorMessage: err.message || '未授权或登录已过期，请重新登录',
      errorCode: 60001,
      data: {},
    };
  }
}